//
//  AppUpdateViewController.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/9/20.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "AppUpdateViewController.h"
#import "ZJAppUpdateAlertView.h"
@interface AppUpdateViewController ()<ZJAppUpdateAlertViewDelegate>
{
    NSDictionary *_appUpdateInfo;
    JCAlertView * alertView;
}
/** imageView */
@property (nonatomic, strong) UIImageView *imageView;
@end

@implementation AppUpdateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.imageView];
    [self netWorking_appUpdate];
    
}

#pragma mark - 代理消失改页面
- (void)delegate_show{
    if (self.delegate) {
        [self.delegate AppUpdateViewControllerDeleGate_show];
    }
}
#pragma mark - 软件更新
- (void)netWorking_appUpdate{
    __weak typeof(self) weakSelf = self;
    [NetWorkingManager appUpdate_Success:^(id object) {
        if ([object objectForKey:@"version"]) {
            [weakSelf appUpdate_Dict:[object objectForKey:@"version"]];
        }else{
            [weakSelf delegate_show];
        }
    } Fail:^(id object) {
            [weakSelf delegate_show];
    }];
}




///版本对比
- (void)appUpdate_Dict:(NSDictionary *)dict{
    _appUpdateInfo = dict;
    //获取应用程序版本号
//    NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
//    NSString *currentVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
//    //网上版本号
//    NSString *newVersionCode = [dict objectForKey:@"versionCode"];
//    if ([newVersionCode floatValue] > [currentVersion floatValue]) {//更新
//        ZJAppUpdateAlertView *view = [[ZJAppUpdateAlertView alloc]initWithFrame:[UIScreen mainScreen].bounds];
//        view.dict = dict;
//        view.delegate = self;
//        alertView = [[JCAlertView alloc] initWithCustomView:view dismissWhenTouchedBackground:YES];
//        [alertView show];
//    }else{//没有更新
        [self delegate_show];
//    }
}

- (void)ZJAppUpdateAlertViewDelegate_canleClick{
    [alertView dismissWithCompletion:^{
        [self delegate_show];
    }];
    
}

- (void)ZJAppUpdateAlertViewDelegate_updateClick{
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[_appUpdateInfo objectForKey:@"path"]]];
    
}


- (UIImageView *)imageView{
    if (_imageView == nil){
        _imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
        _imageView.image = [UIImage imageNamed:@"shibei"];
    }
    return _imageView;
}

@end
